package luo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Description: 创建线程池执行异步任务  被执行任务需要开启@Async注解,
 * @Author:let_free
 * @Date:2024/6/6/15:32
 **/
@Configuration
public class ThreadPoolConfig {
    @Bean(name = "defaultThreadPool")  //定义名称  之后绑定方法的@Async
    public ThreadPoolExecutor threadPoolExecutor()
    {
        return new ThreadPoolExecutor(
                10,
                20,
                60,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(1000),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
    }
}
